package com.vidmt.api.modules.sys.auth.pwdstrategy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vidmt.api.common.utils.AES128Coder;
import com.vidmt.api.common.utils.StrUtil;
import com.vidmt.api.modules.sys.auth.DefaultReversPwdStrategy;

public class AesStrategy extends DefaultReversPwdStrategy {
	private static Logger log = LoggerFactory.getLogger(AesStrategy.class);

	@Override
	protected String getPlainPwd(String rawkey, String ecryptedpwd) {
		AES128Coder des = new AES128Coder(StrUtil.bytesutf8(rawkey));
		return StrUtil.newutf8(des.decrypt(ecryptedpwd));
	}

	@Override
	public String getAlg() {
		return "aes";
	}

	@Override
	public String getCyphered(String rawkey, String plainpwd) {
		AES128Coder des = rawkey == null ? AES128Coder.getDefault() : new AES128Coder(StrUtil.bytesutf8(rawkey));
		return des.encrypt(StrUtil.bytesutf8(plainpwd));
	}
}
